package com.free.app;

import com.free.viewmover.Animator;
import com.free.viewmover.FlipMover;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

public class MoveItemLayout extends FrameLayout
{
	FlipMover mMover;
	Animator mAnimator;
	public MoveItemLayout(Context context)
	{
		super(context);
		
	}
	public MoveItemLayout(Context context, AttributeSet attrs)
	{
		super(context, attrs);
		
	}
	public MoveItemLayout(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		
	}
	
	public void setAnimator(Animator animator)
	{
		mAnimator = animator;
	}
	
	public void setMover(FlipMover mover)
	{
		mMover = mover;
	}
	
	public FlipMover getMover()
	{
		return mMover;
	}
	
	@Override
	public void dispatchDraw (Canvas canvas)
	{
		mMover.move(canvas);
		super.dispatchDraw(canvas);				
		
	}
	
	@Override
	protected void onLayout(boolean changed, int l, int t, int r, int b)
	{
		Rect childRect = mAnimator.getUniformRect();
		int count = getChildCount();
		for (int i = 0; i < count; i++)
		{
		    View child = getChildAt(i);
		    //child.layout(l, t, r, b);
		    child.layout(childRect.left, childRect.top, childRect.right, childRect.bottom);
		}
	}
}
